package io.zhaocy.exception;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * Description:
 *
 * @Author: genezhao
 * @Date: 2018-07-05
 */
@Slf4j
@ControllerAdvice
public class ModuleControllerAdvice {

    private static final Logger SERVICE_LOGGER = LoggerFactory.getLogger(ModuleControllerAdvice.class);

    @ResponseBody
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(ServiceException.class)
    private Result handleServiceException(ServiceException e) {
        String message = "业务受理失败,原因:" + e.getLocalizedMessage();
        SERVICE_LOGGER.info(message);
        Result result = new Result();
        result.setCode(10001);
        result.setMessage(message);
        return result;
    }
}
